package com.dyh.quickdemo.bizDemo.PlatformSplit;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/*
@Author=Joey Wheeler
@Date=2020/11/25 17:11
*/
@Slf4j
public class M {

    public enum  Bundles{
        TAOBAO("TAOBAO"),
        PINDUODUO("PINDUODUO"),
        ALIBABA("DYH","ALIBABA"),
            ;

        public List<String> group;

        Bundles(String... group){
            this.group = Arrays.asList(group);
        }
    }

    List<String> all = Lists.newArrayList("TAOBAO","PINDUODUO",
            "hgc","sfg","DYH","ALIBABA");

    List<List<String>> split(List<String>... groups){
        List<List<String>> res = new ArrayList<>();
        List<String> temp = new ArrayList<>(all);
        for (List<String> group : groups) {
            res.add(group);
            temp.removeAll(group);
        }
        res.add(temp);
        return res;
    }

    List<List<String>> split(){
        List<List<String>> groups = Arrays.stream(Bundles.values()).map(e->e.group)
                .collect(Collectors.toList());

        List<List<String>> res = new ArrayList<>();
        List<String> temp = new ArrayList<>(all);
        for (List<String> group : groups) {
            res.add(group);
            temp.removeAll(group);
        }
        res.add(temp);
        return res;

    }

    @Test
    public void test(){
//        List<List<String>> res = split(
//                Lists.newArrayList("taobao"),
//                Lists.newArrayList("pinduoduo"),
//                Lists.newArrayList("dyh","alibaba")
//                );

        List<List<String>> res = split();

        log.info("res={}",JSON.toJSONString(res));

        log.info("all={}",JSON.toJSONString(all));
    }
}
